package org.example.tomcat.servlets;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

//默认的servlet  当没有匹配的servlet 就会调用这个servlet
@WebServlet(name = "DefaultServlet", urlPatterns = "/")
public class DefaultServlet extends HttpServlet {

    // 处理 GET 请求  默认的父类方法是调用sendErr方法 我选自定义简洁实现 统一让这个处理 返回404
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("do get");
        //实际请求里面 写 分别的 具体逻辑
        response.getOutputStream().write("404 not found".getBytes());

    }

    // 处理 POST 请求
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("do post");

        response.getOutputStream().write("404 not found".getBytes());

    }

}
